GtkWindow: change muxer setup with application
authorRyan Lortie <desrt@desrt.ca>
Wed, 10 Jul 2013 02:33:22 +0000 (22:33 -0400)
committerRyan Lortie <desrt@desrt.ca>
Tue, 15 Oct 2013 13:24:11 +0000 (09:24 -0400)
Previously, GtkWindow would add the "app" action group to its own
toplevel muxer.

Change the setup so that GtkApplication creates the toplevel muxer and
adds itself to it as "app".  Use this muxer as the parent muxer of any
GtkWindow associated with the application.

This saves a small amount of memory and will allow for accels to be
propagated from the application through to all of the windows.

gtk/gtkapplication.c
gtk/gtkapplicationprivate.h
gtk/gtkwidget.c
gtk/gtkwindow.c

index dfd6924c795cecdea1024cef19259557a2e8e08f..b4c9b51066da8a45367b7b740b92d2cd5a79586b 100644 (file)
@@ -143,6 +143,7 @@ struct _GtkApplicationPrivate
   GMenuModel      *menubar;
 
   gboolean register_session;
+  GtkActionMuxer  *muxer;
 
 #ifdef GDK_WINDOWING_X11
   guint next_id;
@@ -396,19 +397,24 @@ gtk_application_focus_in_event_cb (GtkWindow      *window,
 }
 
 static void
-gtk_application_startup (GApplication *application)
+gtk_application_startup (GApplication *g_application)
 {
+  GtkApplication *application = GTK_APPLICATION (g_application);
+
   G_APPLICATION_CLASS (gtk_application_parent_class)
-    ->startup (application);
+    ->startup (g_application);
+
+  application->priv->muxer = gtk_action_muxer_new ();
+  gtk_action_muxer_insert (application->priv->muxer, "app", G_ACTION_GROUP (application));
 
   gtk_init (0, 0);
 
 #ifdef GDK_WINDOWING_X11
-  gtk_application_startup_x11 (GTK_APPLICATION (application));
+  gtk_application_startup_x11 (application);
 #endif
 
 #ifdef GDK_WINDOWING_QUARTZ
-  gtk_application_startup_quartz (GTK_APPLICATION (application));
+  gtk_application_startup_quartz (application);
 #endif
 }
 
@@ -1688,3 +1694,16 @@ gtk_application_is_inhibited (GtkApplication             *application,
 }
 
 #endif
+
+GtkActionMuxer *
+gtk_application_get_parent_muxer_for_window (GtkWindow *window)
+{
+  GtkApplication *application;
+
+  application = gtk_window_get_application (window);
+
+  if (!application)
+    return NULL;
+
+  return application->priv->muxer;
+}
index bd84b1ade342f8f5c11ede69a9e4397e3391bc9f..e0c278a49bd5dfefe259865b98b95a44333175df 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "gtkapplicationwindow.h"
 
+#include "gtkactionmuxer.h"
+
 G_GNUC_INTERNAL
 gboolean                gtk_application_window_publish                  (GtkApplicationWindow *window,
                                                                          GDBusConnection      *session,
@@ -40,4 +42,7 @@ const gchar *           gtk_application_get_app_menu_object_path        (GtkAppl
 G_GNUC_INTERNAL
 const gchar *           gtk_application_get_menubar_object_path         (GtkApplication       *application);
 
+G_GNUC_INTERNAL
+GtkActionMuxer *        gtk_application_get_parent_muxer_for_window     (GtkWindow                *window);
+
 #endif /* __GTK_APPLICATION_PRIVATE_H__ */
index 1f05c8baef776061daa1d6d5f65c6c5f0659b9e3..c4068d1acfc75838118416b2a3d1608be982e2a2 100644 (file)
@@ -64,6 +64,7 @@
 #include "gtkplug.h"
 #include "gtktypebuiltins.h"
 #include "a11y/gtkwidgetaccessible.h"
+#include "gtkapplicationprivate.h"
 
 /* for the use of round() */
 #include "fallback-c89.c"
@@ -15457,18 +15458,26 @@ _gtk_widget_set_style (GtkWidget *widget,
 void
 _gtk_widget_update_parent_muxer (GtkWidget *widget)
 {
-  GtkWidget *parent;
   GtkActionMuxer *parent_muxer;
 
   if (widget->priv->muxer == NULL)
     return;
 
-  if (GTK_IS_MENU (widget))
-    parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
+  if (GTK_IS_WINDOW (widget))
+    {
+      parent_muxer = gtk_application_get_parent_muxer_for_window (GTK_WINDOW (widget));
+    }
   else
-    parent = gtk_widget_get_parent (widget);
+    {
+      GtkWidget *parent;
+
+      if (GTK_IS_MENU (widget))
+        parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
+      else
+        parent = gtk_widget_get_parent (widget);
 
-  parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
+      parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
+    }
 
   gtk_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
 }
index a43372161aab2010a9d5c89f9cf16102777d1059..dfe34f15db17363dfafe3684701cd3dfbf78bdb1 100644 (file)
@@ -2958,8 +2958,7 @@ gtk_window_set_application (GtkWindow      *window,
           gtk_application_add_window (priv->application, window);
         }
 
-      /* don't use a normal cast: application may be NULL */
-      gtk_widget_insert_action_group (GTK_WIDGET (window), "app", (GActionGroup *) application);
+      _gtk_widget_update_parent_muxer (GTK_WIDGET (window));
 
       g_object_notify (G_OBJECT (window), "application");
     }